home *** CD-ROM | disk | FTP | other *** search
/ Internet Info 1994 March / Internet Info CD-ROM (Walnut Creek) (March 1994).iso / answers / rec / puzzles / archive / arithmetic / part1 < prev    next >
Text File  |  1993-08-17  |  65KB  |  1,882 lines

  1. Newsgroups: rec.puzzles,news.answers,rec.answers
  2. Path: senator-bedfellow.mit.edu!bloom-beacon.mit.edu!spool.mu.edu!howland.reston.ans.net!europa.eng.gtefsd.com!uunet!questrel!chris
  3. From: chris@questrel.com (Chris Cole)
  4. Subject: rec.puzzles Archive (arithmetic), part 03 of 35
  5. Message-ID: <puzzles/archive/arithmetic/part1_745653851@questrel.com>
  6. Followup-To: rec.puzzles
  7. Summary: This is part of an archive of questions
  8.  and answers that may be of interest to
  9.  puzzle enthusiasts.
  10.  Part 1 contains the index to the archive.
  11.  Read the rec.puzzles FAQ for more information.
  12. Sender: chris@questrel.com (Chris Cole)
  13. Reply-To: archive-comment@questrel.com
  14. Organization: Questrel, Inc.
  15. References: <puzzles/archive/Instructions_745653851@questrel.com>
  16. Date: Wed, 18 Aug 1993 06:04:31 GMT
  17. Approved: news-answers-request@MIT.Edu
  18. Expires: Thu, 1 Sep 1994 06:04:11 GMT
  19. Lines: 1860
  20. Xref: senator-bedfellow.mit.edu rec.puzzles:24994 news.answers:11514 rec.answers:1914
  21.  
  22. Archive-name: puzzles/archive/arithmetic/part1
  23. Last-modified: 17 Aug 1993
  24. Version: 4
  25.  
  26.  
  27. ==> arithmetic/7-11.p <==
  28. A customer at a 7-11 store selected four items to buy, and was told
  29. that the cost was $7.11.  He was curious that the cost was the same
  30. as the store name, so he inquired as to how the figure was derived.
  31. The clerk said that he had simply multiplied the prices of the four
  32. individual  items.  The customer  protested  that  the four  prices     
  33. should have been ADDED,  not MULTIPLIED.  The  clerk said that that
  34. was OK with him, but, the result was still the same: exactly $7.11.
  35.  
  36. What were the prices of the four items?
  37.  
  38. ==> arithmetic/7-11.s <==
  39. The prices are: $1.20, $1.25, $1.50, and $3.16
  40.  
  41. $7.11 is not the only number which works.  Here are the first 160 such
  42. numbers, preceded by a count of distinct solutions for that price.
  43. Note that $7.11 has a single, unique solution.
  44.  
  45.        1 -  $6.44      1 -  $7.83      2 -  $9.20      3 - $10.89 
  46.        1 -  $6.51      1 -  $7.86      1 -  $9.23      1 - $10.95 
  47.        1 -  $6.60      3 -  $7.92      1 -  $9.24      2 - $11.00 
  48.        1 -  $6.63      1 -  $8.00      1 -  $9.27      1 - $11.07 
  49.        1 -  $6.65      1 -  $8.01      2 -  $9.35      1 - $11.13 
  50.        1 -  $6.72      1 -  $8.03      3 -  $9.36      1 - $11.16 
  51.        2 -  $6.75      5 -  $8.10      1 -  $9.38      1 - $11.22 
  52.        1 -  $6.78      1 -  $8.12      5 -  $9.45      2 - $11.25 
  53.        1 -  $6.80      1 -  $8.16      2 -  $9.48      2 - $11.27 
  54.        2 -  $6.84      2 -  $8.19      1 -  $9.54      1 - $11.30 
  55.        1 -  $6.86      1 -  $8.22      1 -  $9.57      1 - $11.36 
  56.        1 -  $6.89      1 -  $8.25      1 -  $9.59      1 - $11.40 
  57.        2 -  $6.93      3 -  $8.28      2 -  $9.60      2 - $11.43 
  58.        1 -  $7.02      3 -  $8.33      1 -  $9.62      2 - $11.52 
  59.        1 -  $7.05      1 -  $8.36      2 -  $9.63      2 - $11.55 
  60.        2 -  $7.07      1 -  $8.37      1 -  $9.66      2 - $11.61 
  61.        1 -  $7.08      2 -  $8.40      1 -  $9.68      1 - $11.69 
  62.        1 -  $7.11      1 -  $8.45      2 -  $9.69      1 - $11.70 
  63.        1 -  $7.13      2 -  $8.46      1 -  $9.78      1 - $11.88 
  64.        2 -  $7.14      1 -  $8.52      2 -  $9.80      1 - $11.90 
  65.        3 -  $7.20      5 -  $8.55      1 -  $9.81      1 - $11.99 
  66.        1 -  $7.25      1 -  $8.60      1 -  $9.87      1 - $12.06 
  67.        1 -  $7.26      4 -  $8.64      4 -  $9.90      1 - $12.15 
  68.        2 -  $7.28      1 -  $8.67      1 -  $9.92      1 - $12.18 
  69.        1 -  $7.29      1 -  $8.69      2 -  $9.99      1 - $12.24 
  70.        3 -  $7.35      1 -  $8.73      1 - $10.01      1 - $12.30 
  71.        1 -  $7.37      2 -  $8.75      1 - $10.05      1 - $12.32 
  72.        1 -  $7.47      1 -  $8.76      2 - $10.08      1 - $12.35 
  73.        1 -  $7.50      1 -  $8.78      1 - $10.17      2 - $12.42 
  74.        1 -  $7.52      5 -  $8.82      1 - $10.20      1 - $12.51 
  75.        4 -  $7.56      1 -  $8.85      2 - $10.26      1 - $12.65 
  76.        1 -  $7.62      1 -  $8.88      3 - $10.29      2 - $12.69 
  77.        4 -  $7.65      2 -  $8.91      3 - $10.35      1 - $12.75 
  78.        1 -  $7.67      1 -  $8.94      2 - $10.44      1 - $12.92 
  79.        2 -  $7.70      1 -  $8.96      1 - $10.53      1 - $12.96 
  80.        3 -  $7.74      3 -  $9.00      1 - $10.56      1 - $13.23 
  81.        1 -  $7.77      1 -  $9.02      1 - $10.64      1 - $13.41 
  82.        1 -  $7.79      2 -  $9.03      2 - $10.71      1 - $13.56 
  83.        2 -  $7.80      1 -  $9.12      3 - $10.80      1 - $14.49 
  84.        1 -  $7.82      2 -  $9.18      1 - $10.85      1 - $15.18 
  85.  
  86.  
  87. There are plenty of solutions for five summands.  Here are a few:
  88.  
  89.          $8.28  -- at least two solutions
  90.          $8.47  -- at least two solutions
  91.          $8.82  -- at least two solutions
  92. --
  93.      Mark Johnson       mark@microunity.com       (408) 734-8100
  94.  
  95. There may be many approximate solutions, for example: $1.01, $1.15, $2.41,
  96. and $2.54.  These sum to $7.11 but the product is 7.1100061.
  97.  
  98. ==> arithmetic/arithmetic.progression.p <==
  99. Is there an arithmetic progression of 20 or more primes?
  100.  
  101. ==> arithmetic/arithmetic.progression.s <==
  102. There is an arithmetic progression of 21 primes:
  103.     142072321123 + 1419763024680 i, 0 <= i < 21.
  104.  
  105. It was discovered on 30 November 1990, by programs running in the background
  106. on a network of Sun 3 workstations in the Department of Computer Science,
  107. University of Queensland, Australia.
  108.  
  109. See: Andrew Moran and Paul Pritchard, The design of a background job
  110. on a local area network, Procs. 14th Australian Computer Science Conference,
  111. 1991, to appear.
  112.  
  113. ==> arithmetic/clock/day.of.week.p <==
  114. It's restful sitting in Tom's cosy den, talking quietly and sipping
  115. a glass of his Madeira.
  116.  
  117. I was there one Sunday and we had the usual business of his clock.
  118. When the radio gave the time at the hour, the Ormolu antique was 
  119. exactly 3 minutes slow.
  120.  
  121. "It loses 7 minutes every hour", my old friend told me, as he had done
  122. so many times before.  "No more and no less, but I've gotten used to
  123. it that way."
  124.  
  125. When I spent a second evening with him later that same month, I remarked
  126. on the fact that the clock was dead right by radio time at the hour.
  127. It was rather late in the evening, but Tom assured me that his treasure
  128. had not been adjusted nor fixed since my last visit.
  129.  
  130. What day of the week was the second visit?
  131.  
  132. From "Mathematical Diversions" by Hunter + Madachy
  133.  
  134. ==> arithmetic/clock/day.of.week.s <==
  135. The answer is 17 days and 3 hours later, which would have been a Wednesday.
  136. This is the only other time in the same month when the two would agree at all.
  137.  
  138. In 17 days the slow clock loses 17*24*7 minutes = 2856 minutes,
  139. or 47 hours and 36 minutes.  In 3 hours more it loses 21 minutes, so
  140. it has lost a total of 47 hours and 57 minutes.  Modulo 12 hours, it
  141. has *gained* 3 minutes so as to make up the 3 minutes it was slow on
  142. Sunday.  It is now (fortnight plus 3 days) exactly accurate.
  143.  
  144. Since the clock was not adjusted since the last visit, it's also
  145. possible that the radio time shifted by one hour due to a change to or
  146. from summer daylight saving time.  However, it turns out that the only
  147. additional possibilities that need to be considered are those of 4 days
  148. 15 hours later, when the clock would have lost 12 hours 57 minutes, and
  149. 29 days 15 hours later, when the clock would have lost 3 days 10 hours
  150. 57 minutes.  Without even considering the rules for when in the month the
  151. clock is changed, these possible solutions are ruled out because we know
  152. that both visits were in the evening ("I spent a second evening with him").
  153. and they involve times in a different part of the day.
  154.  
  155.  
  156. ==> arithmetic/clock/palindromic.p <==
  157. How many times per day does a digital clock display a palindromic number?
  158.  
  159.  
  160. ==> arithmetic/clock/palindromic.s <==
  161. The problem is underspecified.  Digital clocks may run from
  162.  
  163.     (a) 1:00 to 12:59
  164.     (b) 01:00 to 12:59
  165.     (c) 0:00 to 23:59
  166.     (d) 00:00 to 23:59
  167.     (e-h) any of the above with seconds appended, :00 to :59.
  168.  
  169. I agree that not all of these are common, but I have seen some uncommon
  170. ones.  For that matter, I've seen ones not on the above list -- the Toronto
  171. subway stations used to contain digital clocks that ran from 0:00 to 12:59
  172. (pm), then from 1:00 (pm) to 11:59 (pm), while a computer that I used to
  173. use had the inverse anomaly -- its time of day command displayed times
  174. from 12:00:00 to 12:59:59 (am), then 01:00:00 to 23:59:59!
  175.  
  176. I get the following results for the 8 cases.
  177.  
  178.     CASE    AM+PM    HOURS pals/hr  TOTAL    OVERALL TOTAL
  179.     (a)    yes    1-9     6     54
  180.             10-12     1      3    114
  181.   
  182.     (b)    yes    01-05     1      5
  183.             06-09     0      0
  184.             10-12     1      3    16
  185.  
  186.     (c)    no    0-9     6     60
  187.             10-15     1      6
  188.             16-19     0      0
  189.             20-23     1      4    70
  190.  
  191.     (d)    no    00-05     1      6
  192.             06-09     0      0
  193.             10-15     1      6
  194.             16-19     0      0
  195.             20-23     1      4    16
  196.  
  197.     (e)    yes    1-9    60    540
  198.             10-12     6     18    1116
  199.  
  200.     (f)    yes    01-05     6     30
  201.             06-09     0      0
  202.             10-12     6     18    96
  203.  
  204.     (g)    no    0-9    60    600
  205.             10-15     6     36
  206.             16-19     0      0
  207.             20-23     6     24    660
  208.  
  209.     (h)    no    00-05     6     36
  210.             06-09     0      0
  211.             10-15     6     36
  212.             16-19     0      0
  213.             20-23     6     24    96
  214.  
  215. --Mark Brader (msb@sq.com)
  216.  
  217. ==> arithmetic/clock/reversible.p <==
  218. How many times per day can the hour and minute hands on an analog clock switch
  219. roles and still signify a valid time, ignoring the second hand?
  220.  
  221. ==> arithmetic/clock/reversible.s <==
  222. Have 12 clocks C1, C2 ... C12 show 1:00, 2:00, ..., 12:00.  Have a
  223. clock C0 show 12:00
  224.  
  225. Now turn C0 around 12 hours, simultaneously turning C1-C12 so their
  226. hour hands always coincide with the minute hand of C0, i.e., as C0
  227. spans 12 hours, C1-C12 will span 1 hour, but for each possible placing
  228. of the hour hand, all 12 possible 'true' placings of the minute hand
  229. will be represented by one of the 12 clocks.
  230.  
  231. Each time the hour hand of C0 coincides with the minute hand of a
  232. C1-C12 clock we have a reversible valid time.  This happens regularly
  233. 12 times each C0 hour, but the first and last time is equal (12:00), so
  234. the number of reversible true times is 12*12-1 = 143 spaced regularly
  235. in the 12-hour interval, ie. each 5 min 2.0979+ sec
  236.  
  237. -- 
  238. stein.kulseth@tf.tele.no [X.400] stein.kulseth@nta.no [internet]
  239.  
  240. ==> arithmetic/clock/right.angle.p <==
  241. How many times per day do the hour and minute hands of a clock form a
  242. right angle?
  243.  
  244.  
  245. ==> arithmetic/clock/right.angle.s <==
  246. 44.  Twice each hour equals 48, less one between 2:00 and 4:00 and one between
  247. 8:00 and 10:00 for both A.M. and P.M.
  248.  
  249. ==> arithmetic/clock/thirds.p <==
  250. Do the 3 hands on a clock ever divide the face of the clock into 3
  251. equal segments, i.e. 120 degrees between each hand?       
  252.  
  253. ==> arithmetic/clock/thirds.s <==
  254. First let us assume that our clock has 60 divisions.  We will show that
  255. any time the hour hand and the minute hand are 20 divisions (120 degrees)
  256. apart, the second hand cannot be an integral number of divisions from the
  257. other hands, unless it is straight up (on the minute).
  258.  
  259. Let us use h for hours, m for minutes, and s for seconds.
  260. We will use =n to mean congruent mod n, thus 12 =5 7.
  261.  
  262. We know that m =60 12h, that is, the minute hand moves 12 times as fast
  263. as the hour hand, and wraps around at 60.
  264. We also have s =60 60m. This simplifies to s/60 =1 m, which goes to
  265. s/60 = frac(m) (assuming s is in the range 0 <= s < 60), which goes to
  266. s = 60 frac(m).  Thus, if m is 5.5, s is 30.
  267.  
  268. Now let us assume the minute hand is 20 divisions ahead of the hour hand.
  269. So m =60 h + 20, thus 12h =60 h + 20, 11h =60 20, and, finally,
  270. h =60/11 20/11 (read 'h is congruent mod 60/11 to 20/11').
  271. So all values of m are k + n/11 for some integral k and integral n,
  272. 0 <= n < 11.  s is therefore 60n/11.  If s is to be an integral number of
  273. units from m and h, we must have 60n =11 n.  But 60 and 11 are relatively
  274. prime, so this holds only for n = 0.  But if n = 0, m is integral, so
  275. s is 0.
  276.  
  277. Now assume, instead, that the minute hand is 20 divisions behind the hour hand.
  278. So m =60 h - 20, 12h =60 h - 20, 11h =60 -20, h =60/11 -20/11.
  279. So m is still k + n/11.  Thus s must be 0.
  280.  
  281. But if s is 0, h must be 20 or 40.  But this translates to 4 o'clock or
  282. 8 o'clock, at both of which the minute hand is at 0, along with the second
  283. hand.
  284.  
  285. Thus the 3 hands can never be 120 degrees apart, Q.E.D.
  286.  
  287. This assumes, of course, that the second hand is synchronized with the
  288. minute hand.  This is not true on some inexpensive analog watches.  This
  289. also assumes that the watch is not broken (:^)).
  290.  
  291. ==> arithmetic/consecutive.composites.p <==
  292. Are there 10,000 consecutive non-prime numbers?
  293.  
  294. ==> arithmetic/consecutive.composites.s <==
  295. 9973!+2 through 9973!+10006 are composite.
  296.  
  297. ==> arithmetic/consecutive.product.p <==
  298. Prove that the product of three or more consecutive positive integers cannot
  299. be a perfect square.
  300.  
  301. ==> arithmetic/consecutive.product.s <==
  302. Three consecutive numbers:
  303.   If a and b are relatively prime, and ab is a square,
  304.   then a and b are squares. (This is left as an exercise.)
  305.  
  306.   Suppose (n - 1)n(n + 1) = k^2, where n > 1.  
  307.   Then n(n^2 - 1) = k^2.  But n and (n^2 - 1) are relatively prime.
  308.   Therefore n^2 - 1 is a perfect square, which is a contradiction.
  309.  
  310. Four consecutive numbers:
  311.   n(n + 1)(n + 2)(n + 3) = (n^2 + 3n + 1)^2 - 1
  312.  
  313. Five consecutive numbers:
  314.   Assume the product is a integer square, call it m.
  315.  
  316.   The prime factorization of m must have even numbers of each prime factor.
  317.  
  318.   For each prime factor, p, of m, p >= 5, p^2k must divide one of the
  319. consecutive naturals in the product.  (Otherwise, the difference between two
  320. of the naturals in the product would be a positive multiple of a prime >= 5.
  321. But in this problem, the greatest difference is 4.) So we need only consider
  322. the primes 2 and 3.
  323.  
  324.   Each of the consecutive naturals is one of:
  325.     1)    a perfect square
  326.     2)    2 times a perfect square
  327.     3)    3 times a perfect square
  328.     4)    6 times a perfect square.
  329.  
  330.   By the shoe box principle, two of the five consecutive numbers must fall into
  331. the same category.
  332.  
  333.   If there are two perfect squares, then their difference being less than five
  334. limits their values to be 1 and 4.  (0 is not a natural number, so 0 and 1
  335. and 0 and 4 cannot be the perfect squares.)  But 1*2*3*4*5=120!=x*x where x
  336. is an integer.
  337.  
  338.   If there are two numbers that are 2 times a perfect square, then their
  339. difference being less than five implies that the perfect squares (which are
  340. multiplied by 2) are less than 3 apart, and no two natural squares differ by
  341. only 1 or 2.
  342.  
  343.   A similar argument holds for two numbers which are 3 times a perfect square.
  344.  
  345.   We cannot have the case that two of the 5 consecutive numbers are multiples
  346. (much less square multiples) of 6, since their difference would be >= 6, and
  347. our span of five consecutive numbers is only 4.
  348.  
  349.   Therefore the assumption that m is a perfect square does not hold.
  350.  
  351.   QED.
  352.  
  353. In general the equation:
  354.  
  355. y^2 = x(x+1)(x+2)...(x+n),    n > 3
  356.  
  357. has only the solution corresponding to y = 0.
  358.  
  359. This is a theorem of Rigge [O. Rigge, ``Uber ein diophantisches Problem'',
  360. IX Skan. Math. Kong. Helsingfors (1938)] and Erdos [P. Erdos, ``Note on
  361. products of consecutive integers,'' J. London Math. Soc. #14 (1939),
  362. pages 194-198].
  363.  
  364. A proof can be found on page 276 of [L. Mordell, ``Diophantine
  365. Equations'', Academic Press 1969].
  366.  
  367. ==> arithmetic/consecutive.sums.p <==
  368. Find all series of consecutive positive integers whose sum is exactly 10,000.
  369.  
  370. ==> arithmetic/consecutive.sums.s <==
  371. Generalize to find X (and I) such that
  372.     (X + X+1 + X+2 + ... + X+I) = T
  373. for any integer T.
  374.  
  375. You are asking for all (X,I) s.t. (2X+I)(I+1) = 2T.  The problem is
  376. (very) slightly easier if we don't restrict X to being positive, so
  377. we'll solve this first.
  378.  
  379. Note that 2X+I and I+1 must have different parities, so the answer
  380. to the relaxed question is N = 2*(o_1+1)*(o_2+1)*...*(o_n+1), where
  381. 2T = 2^o_0*3^o_1*...*p_n^o_n (the prime factorization); this is easily
  382. seen to be the number of ways we can break 2T up into two positive
  383. factors of differing parity (with order).
  384.  
  385. In particular, 20000 = 2^5*5^4, hence there are 2*(4+1) = 10 solutions
  386. for T = 10000.  These are (2X+I,I+1):
  387.  
  388. (32*1,5^4)   (32*5,5^3)   (32*5^2,5^2)   (32*5^3,5)   (32*5^4,1)
  389. (5^4,32*1)   (5^3,32*5)   (5^2,32*5^2)   (5,32*5^3)   (1,32*5^4)
  390.  
  391. And they give rise to the solutions (X,I):
  392.  
  393. (-296,624)   (28,124)   (388,24)   (1998,4)     (10000,0)
  394. (297,31)     (-27,179)  (-387,799) (-1997,3999) (-9999,19999)
  395.  
  396. If you require that X>0 note that this is true iff 2X+I > I+1 and
  397. hence the number of solutions to this problem is N/2 (due to the
  398. symmetry of the above ordered pairs).
  399.  
  400. ==> arithmetic/conway.p <==
  401. Describe the sequence a(1)=a(2)=1, a(n) = a(a(n-1)) + a(n-a(n-1)) for n>2.
  402.  
  403. ==> arithmetic/conway.s <==
  404. This sequence and its remarkable properties were discovered, apparently
  405. independently, by Douglas Hofstadter (circa 1975), John Conway (in the
  406. early 1980's), B.W. Connoly, and others. Since Conway discovered many of
  407. the deeper properties, and is the one responsible for popularizing the
  408. sequence, it seems appropriate to name the sequence after him.
  409.  
  410. Some properties of a(n):
  411.  
  412. --  a(n+1) - a(n) = 0 or 1
  413.  
  414. --  a(2^n) = 2^(n-1)
  415.  
  416. --  n/2 <= a(n) <= n
  417.  
  418. --  A(n)= 2a(n) - n    has zeros at the powers of 2 and 
  419.      positive "humps" in between
  420.  
  421. --  A(2^n + t) = A(2^(n+1) - t)  for t between 0 and 2^n,
  422.      i.e. the humps are symmetric
  423.  
  424. -- a(2n) <= 2a(n)
  425.  
  426. -- a(n)/n --> 1/2  as  n --> infinity
  427.  
  428. -- a(n) and A(n) are self-similar, in the sense that their values on the
  429.    (N+1)'st hump can be obtained by a "magnification" process applied
  430.    to the values on the N'th hump. They are *not* chaotic sequences,
  431.    since their asymptotics and combinatorial structure are very regular
  432.    and rigid.
  433.  
  434. In a lecture at Bell Labs in 1988, Conway asked for the rate at
  435. which  a(n)/n converges to 1/2.  In particular, he asked for
  436. N(epsilon), the last value of  n  such that  |a(n)/n - 1/2|
  437. exceeds epsilon, in the case  epsilon=1/20.  This problem was
  438. solved by Colin Mallows of Bell Labs: he found that  N(1/20)=1489
  439. and N(1/40)=6083008742. These values are reported in his article
  440. in the American Mathematical Monthly, January 1991, p. 5.
  441.  
  442. Conway's sequence has a deep combinatorial structure, and is intimately
  443. connected with all of the following: variants of Pascal's triangle, the
  444. Gaussian distribution, combinatorial operations on finite sets,
  445. coin-pushing games, and Fibonacci and Catalan numbers.  All of this is
  446. explained in my joint paper with Ravi Vakil; anyone who would like to
  447. receive a copy in LaTex format should contact me at the e-mail address
  448. listed below.
  449.  
  450. One byproduct of our work is an algorithm to determine  N(epsilon) for
  451. given positive epsilon.  Here are some particular values:
  452.  
  453.  e      Last  n  such that   |a(n)/n - 1/2| > e
  454. ----    ----------------------------------------------------------
  455. 1/20    1489  (found by Mallows in 1988)
  456. 1/30    758765
  457. 1/40    6083008742  (found by Mallows in 1988)
  458. 1/50    809308036481621
  459. 1/60    1684539346496977501739
  460. 1/70    55738373698123373661810220400
  461. 1/80    15088841875190938484828948428612052839
  462. 1/90    127565909103887972767169084026274554426122918035
  463. 1/100   8826608001127077619581589939550531021943059906967127007025
  464.  
  465. These values were computed by the Mathematica program listed below; the
  466. algorithm is explained in our paper.  To use the program, load it into
  467. Mathematica and type   neps[t]  for some numerical value of  t  (which
  468. should probably be smaller than 1/5 or so). The program will output  N(t),
  469. e.g.  neps[1/20] = 1489. These numbers grow very fast: N(epsilon) will be
  470. about 2^((0.138015/epsilon)^2), so  N(1/1000) will have about 5735 digits.
  471. The program requires very little memory space, but its runtime appears to
  472. grow rapidly as epsilon decreases (on a Sun 3, it took about one second to
  473. find the first value listed, and several minutes to find the last).
  474.  
  475. neps[eps_] := Block[{W}, L = 1 + Floor[(0.138015/eps)^2]; e = eps*2; 
  476.     W = processvector[L]; While[Length[W] > 0, 
  477.      nmax = 1 + Last[W][[4]]; L++; W = processvector[L]]; nmax]
  478.  
  479. processvector[L_] := 
  480.   Block[{V}, V = startvector[L]; While[notfound[V], V = newbody[V]]; V]
  481.  
  482. startvector[L_] := Select[initialvector[L], gt]
  483.  
  484. initialvector[L_] := 
  485.   Table[{L, b, Binomial[L - 1, b - 1], 
  486.     2^(L + 1) - Sum[Binomial[L, c], {c, b, L}]}, {b, 0, L - 1}]
  487.  
  488. c[0] = 0
  489.  
  490. c[n_] := c[n] = Sum[Binomial[2*a, a]/(a + 1), {a, 0, n - 1}]
  491.  
  492. gt[x_] := U[x] > e
  493.  
  494. U[x_] := (x[[3]] + M[x[[1]], x[[2]]])/(x[[4]] + incp[x[[1]], x[[2]]])
  495.  
  496. M[n_, n_] = -1
  497.  
  498. M[n_, k_] := Binomial[n - 1, K[n, k]] - Binomial[n - 1, k - 1] + c[K[n, k]]
  499.  
  500. K[n_, k_] := Min[k, n - k]
  501.  
  502. incp[n_, k_] := Max[M[n, k], 1]
  503.  
  504. notfound[V_] := 
  505.   Length[V] > 0 && Last[V][[2]] > 0 && Last[V][[1]] > Last[V][[2]]
  506.  
  507. newbody[V_] := Join[Drop[V, -1], newtail[V]]
  508.  
  509. newtail[V_] := Select[{vleft[Last[V]], vright[Last[V]]}, gt]
  510.  
  511. vleft[x_] := {x[[1]] - 1, x[[2]] - 1, x[[3]], x[[4]]}
  512.  
  513. vright[x_] := {x[[1]] - 1, x[[2]], x[[3]] + S[x[[1]] - 1, x[[2]] - 1], 
  514.    x[[4]] + Binomial[x[[1]] - 1, x[[2]] - 1]}
  515.  
  516. S[n_, k_] := Binomial[n - 1, k] - Binomial[n - 1, k - 1]
  517.  
  518.  
  519. -Tal Kubo     kubo@math.harvard.edu  or   kubo@zariski.harvard.edu
  520.  
  521. ==> arithmetic/digits/6.and.7.p <==
  522. Does every number which is not divisible by 5 have a multiple whose
  523. only digits are 6 and 7?
  524.  
  525. ==> arithmetic/digits/6.and.7.s <==
  526. Yes.  My proof follows:
  527.  
  528. Claim 1: For every k, there is a k-digit number whose only digits
  529. are 6 and 7, which is divisible by 2^k.
  530.  
  531. The proof is by induction.  Suppose N is a k-digit number 
  532. satisfying the above condition.  Then either N = 0 (mod 2^(k+1))
  533. or N = 2^k (mod 2^(k+1)). Note that 6(10^k) = 0 (mod 2^(k+1)),
  534. and 7(10^k) = 2^k (mod 2^(k+1)).  So, either 6*10^k + N or
  535. 7*10^k + N is divisible by 2^(k+1).
  536.  
  537. Claim 2:  If m and 10 are relatively prime, then for any r,
  538. there is a number N whose only digits are 6 and 7 such that
  539. N = r (mod m). 
  540.  
  541. Proof:  Let K be the (m^2)-digit number whose only digit is 6.
  542. There is an s, 0 <= s < m, so that K + s = r (mod m).
  543. Let N = K + 10^(m - 1) + 10^(2m - 2) + . . . + 10^(sm - s).
  544. Since 10^(im - i) = 1 (mod m), N = K + s (mod m) = r (mod m).
  545. Clearly, every digit of N is either 6 or 7. 
  546.  
  547. Claim 3: If n is not divisible by 5, then there is a number N whose
  548. only digits are 6 and 7, so that N is divisible by n. 
  549.  
  550. Proof:  We can write n = (2^k)m, with gcd(m,10)=1.
  551. Use claim 1 to find a k-digit number M, whose only digits are 6 and 7,
  552. which is divisible by 2^k.  Choose an integer r so that
  553. (10^k)r + M = 0 (mod m).  Use claim 2 to find a number K whose
  554. only digits are 6 and 7, so that K = r (mod m).  Let N = 10^k K + M.
  555. Then N = 0 (mod m) and N = 0 (mod 2^k), so N is divisible by n.
  556. Finally, the only digits of N are 6 and 7, so we are done.
  557.  
  558. --
  559. David Radcliffe                                radcliff@csd4.csd.uwm.edu
  560.  
  561. ==> arithmetic/digits/all.ones.p <==
  562. Prove that some multiple of any integer ending in 3 contains all 1s.
  563.  
  564. ==> arithmetic/digits/all.ones.s <==
  565. Let n be our integer; one such desired multiple is then
  566. (10^(phi(n))-1)/9.  All we need is that (n,10) = 1, and if the last
  567. digit is 3 this must be the case.  A different proof using the
  568. pigeonhole principle is to consider the sequence 1, 11, 111, ..., (10^n
  569. - 1)/9.  We must have at some point that either some member of our
  570. sequence = 0 (mod n) or else some value (mod n) is duplicated.  Assume
  571. the latter, with x_a and x_b, x_b>x_a,  possesing the duplicated
  572. remainders.  We then have that x_b - x-a = 0 (mod n).  Let m be the
  573. highest power of 10 dividing x_b - x_a.  Now since (10,n) = 1, we can
  574. divide by 10^m and get that (x_b - x_a)/10^m = 0 (n).  But (x_b -
  575. x_a)/10^m is a number containing only the digit 1.
  576.  
  577. Q.E.D.
  578.  
  579. ==> arithmetic/digits/arabian.p <==
  580. What is the Arabian Nights factorial, the number x such that x! has 1001
  581. digits?  How about the prime x such that x! has exactly 1001 zeroes on
  582. the tail end.  (Bonus question, what is the 'rightmost' non-zero digit in x!?)
  583.  
  584. ==> arithmetic/digits/arabian.s <==
  585. The first answer is 450!.
  586.  
  587. Determining the number of zeroes at the end of x! is relatively easy once
  588. you realize that each such zero comes from a factor of 10 in the product
  589.  
  590.    1 * 2 * 3 * ... * x
  591.  
  592. Each factor of 10, in turn, comes from a factor of 5 and a factor of 2.
  593. Since there are many more factors of 2 than factors of 5, the number of 5s
  594. determines the number of zeroes at the end of the factorial.
  595.  
  596. The number of 5s in the set of numbers 1 .. x (and therefore the number
  597. of zeroes at the end of x!) is:
  598.  
  599.   z(x) = int(x/5) + int(x/25) + int(x/125) + int(x/625) + ...
  600.  
  601. This series terminates when the powers of 5 exceed x.
  602.  
  603. I know of no simple way to invert the above formula (i.e., to find x for
  604. a given z(x)), but I can approximate it by noting that, except for the "int"
  605. function,
  606.  
  607.    5*z(x) - x = z(x)
  608.  
  609. which gives:
  610.  
  611.    x = 4*z(x) (approximately).
  612.  
  613. The given problem asked, "For what prime x is z(x)=1001".  By the above forumla,
  614. this is approximately 4*1001=4004.  However, 4004! has only
  615.  
  616.   800 + 160 + 32 + 6 + 1 = 999 zeroes at the end of it.
  617.  
  618. The numbers 4005! through 4009! all have 1000 zeroes at their end and
  619. the numbers 4010! through 4014! all have 1001 zeroes at their end.
  620.  
  621. Since the problem asked for a prime x, and 4011 = 3*7*191, the only solution
  622. is x=4013.
  623.  
  624. The problem of determining the rightmost nonzero digit in x! is somewhat more
  625. difficult.  If we took the numbers 1, 2, ... , x and removed all factors of 5
  626. (and an equal number of factors of 2), the remaining numbers multiplied
  627. together modulo 10 would be the answer.  Note that since there are still many
  628. factors of 2 left, the rightmost nonzero digit must be 2, 4, 6, or 8 (x > 1).
  629.  
  630. Letting r(x) be the rightmost nonzero digit in x!, an expression for r(x) is:
  631.  
  632.   r(x) = (r(int(x/5)) * w * r(x mod 10)) mod 10, x >= 10.
  633.  
  634. where w is 4 if int(x/10) is odd and 6 if it is even.
  635.  
  636. The values of r(x) for 0 <= x <= 9 are 1, 1, 2, 6, 4, 2, 2, 4, 2, and 8.
  637.  
  638. The way to see this is true is to take the numbers 1, 2, ..., x in groups
  639. of 10.  In each group, remove 2 factors of 10.  For example, from the
  640. set 1, 2, ..., 10, choose a factor of 2 from 2 and 6 and a factor of 5 from
  641. 5 and 10.  This leaves 1, 1, 3, 4, 1, 3, 7, 8, 9, 2.  Next, separate all the
  642. factors that came from multiples of 5.  The rightmost nonzero digit of x!
  643. can now (hopefully) be seen to be:
  644.  
  645.   r(x) = (r(int(x/5)) * w * r(x mod 10)) mod 10
  646.  
  647. where w is the rightmost digit in the number formed by multiplying the numbers
  648. 1, 2, 3, ..., 10*int(x/10) after the factors of 10 and the factors left over
  649. by the multiples of 5 have been removed.  In the example with x = 10, this
  650. would be (1 * 1 * 3 * 4 * 3 * 7 * 8 * 9) mod 10 = 4.  The "r(x mod 10)" term
  651. takes care of the numbers from 10*int(x/10)+1 up to x.
  652.  
  653. The "w" term can be seen to be 4 or 6 depending on whether int(x/10) is odd or
  654. even since, after removing 10*n+5 and 10*n+10 and a factor of 2 each from
  655. 10*n+2 and 10*n+6 from the group of numbers 10*n+1 through 10*n+10, the
  656. remaining factors (mod 10) always equals 4 and 4^t mod 10 = 4 if t is odd and
  657. 6 when t is even (t != 0).
  658.  
  659. So, finally, the rightmost nonzero digit in 4013! is found as follows:
  660.  
  661.   r(4013) = (r(802) * 4 * 6) mod 10
  662.   r(802)  = (r(160) * 6 * 2) mod 10
  663.   r(160)  = (r(32)  * 6 * 1) mod 10
  664.   r(32)   = (r(6)   * 4 * 2) mod 10
  665.  
  666. Using a table of r(x) for 0 <= x <= 9, r(6) = 2.  Then,
  667.  
  668.   r(32)   = (2 * 4 * 2) mod 10 = 6
  669.   r(160)  = (6 * 6 * 1) mod 10 = 6
  670.   r(802)  = (6 * 6 * 2) mod 10 = 2
  671.   r(4013) = (2 * 4 * 6) mod 10 = 8
  672.  
  673. Thus, the rightmost nonzero digit in 4013! is 8.
  674.  
  675. ==> arithmetic/digits/circular.p <==
  676. What 6 digit number, with 6 different digits, when multiplied by all integers
  677. up to 6, circulates its digits through all 6 possible positions, as follows:
  678. ABCDEF * 1 = ABCDEF
  679. ABCDEF * 3 = BCDEFA
  680. ABCDEF * 2 = CDEFAB
  681. ABCDEF * 6 = DEFABC
  682. ABCDEF * 4 = EFABCD
  683. ABCDEF * 5 = FABCDE
  684.  
  685. ==> arithmetic/digits/circular.s <==
  686. ABCDEF=142857 (the digits of the expansion of 1/7).
  687.  
  688. ==> arithmetic/digits/divisible.p <==
  689. Find the least number using 0-9 exactly once that is evenly divisible by each
  690. of these digits.
  691.  
  692. ==> arithmetic/digits/divisible.s <==
  693. Since the sum of the digits is 45, any permutation of the digits gives a
  694. multiple of 9.  To get a multiple of both 2 and 5, the last digit must
  695. be 0, and thus to get a multiple of 8 (and 4), the tens digit must be
  696. even, and the hundreds digit must be odd if the tens digit is 2 or 6,
  697. and even otherwise.  The number will also be divisible by 6, since it is
  698. divisible by 2 and 3, so 7 is all we need to check.  First, we will look
  699. for a number whose first five digits are 12345; now, 1234500000 has a
  700. remainder of 6 when divided by 7, so we have to arrange the remaining
  701. digits to get a remainder of 1.  The possible arrangements, in
  702. increasing order, are
  703.  
  704. 78960, remainder 0
  705. 79680, remainder 6
  706. 87960, remainder 5
  707. 89760, remainder 6
  708. 97680, remainder 2
  709. 98760, remainder 4
  710.  
  711. That didn't work, so try numbers starting with 12346; this is impossible
  712. because the tens digit must be 8, and the hundreds digit cannot be even.
  713. Now try 12347, and 1234700000 has remainder 2.  The last five digits can
  714. be
  715.  
  716. 58960, remainder 6
  717. 59680, remainder 5, so this works, and the number is
  718.  
  719. 1234759680.
  720.  
  721. ==> arithmetic/digits/equations/123456789.p <==
  722. In how many ways can "." be replaced with "+", "-", or "" (concatenate) in
  723. .1.2.3.4.5.6.7.8.9=1 to form a correct equation?
  724.  
  725. ==> arithmetic/digits/equations/123456789.s <==
  726.  1-2 3+4 5+6 7-8 9 = 1
  727. +1-2 3+4 5+6 7-8 9 = 1
  728.  1+2 3+4-5+6 7-8 9 = 1
  729. +1+2 3+4-5+6 7-8 9 = 1
  730. -1+2 3-4+5+6 7-8 9 = 1
  731.  1+2 3-4 5-6 7+8 9 = 1
  732. +1+2 3-4 5-6 7+8 9 = 1
  733.  1-2 3-4+5-6 7+8 9 = 1
  734. +1-2 3-4+5-6 7+8 9 = 1
  735.  1-2-3-4 5+6 7-8-9 = 1
  736. +1-2-3-4 5+6 7-8-9 = 1
  737.  1+2-3 4+5 6-7-8-9 = 1
  738. +1+2-3 4+5 6-7-8-9 = 1
  739. -1+2 3+4+5-6-7-8-9 = 1
  740. -1 2+3 4-5-6+7-8-9 = 1
  741.  1+2+3+4-5+6+7-8-9 = 1
  742. +1+2+3+4-5+6+7-8-9 = 1
  743. -1+2+3-4+5+6+7-8-9 = 1
  744.  1-2-3+4+5+6+7-8-9 = 1
  745. +1-2-3+4+5+6+7-8-9 = 1
  746.  1+2 3+4 5-6 7+8-9 = 1
  747. +1+2 3+4 5-6 7+8-9 = 1
  748.  1+2 3-4-5-6-7+8-9 = 1
  749. +1+2 3-4-5-6-7+8-9 = 1
  750.  1+2+3+4+5-6-7+8-9 = 1
  751. +1+2+3+4+5-6-7+8-9 = 1
  752. -1+2+3+4-5+6-7+8-9 = 1
  753.  1-2+3-4+5+6-7+8-9 = 1
  754. +1-2+3-4+5+6-7+8-9 = 1
  755. -1-2-3+4+5+6-7+8-9 = 1
  756.  1-2+3+4-5-6+7+8-9 = 1
  757. +1-2+3+4-5-6+7+8-9 = 1
  758.  1+2-3-4+5-6+7+8-9 = 1
  759. +1+2-3-4+5-6+7+8-9 = 1
  760. -1-2+3-4+5-6+7+8-9 = 1
  761. -1+2-3-4-5+6+7+8-9 = 1
  762. -1+2 3+4 5-6 7-8+9 = 1
  763.  1-2 3-4 5+6 7-8+9 = 1
  764. +1-2 3-4 5+6 7-8+9 = 1
  765. -1+2 3-4-5-6-7-8+9 = 1
  766. -1+2+3+4+5-6-7-8+9 = 1
  767.  1-2+3+4-5+6-7-8+9 = 1
  768. +1-2+3+4-5+6-7-8+9 = 1
  769.  1+2-3-4+5+6-7-8+9 = 1
  770. +1+2-3-4+5+6-7-8+9 = 1
  771. -1-2+3-4+5+6-7-8+9 = 1
  772.  1+2-3+4-5-6+7-8+9 = 1
  773. +1+2-3+4-5-6+7-8+9 = 1
  774. -1-2+3+4-5-6+7-8+9 = 1
  775. -1+2-3-4+5-6+7-8+9 = 1
  776.  1-2-3-4-5+6+7-8+9 = 1
  777. +1-2-3-4-5+6+7-8+9 = 1
  778.  1-2 3+4+5+6+7-8+9 = 1
  779. +1-2 3+4+5+6+7-8+9 = 1
  780.  1+2+3+4 5-6 7+8+9 = 1
  781. +1+2+3+4 5-6 7+8+9 = 1
  782.  1 2+3 4+5-6 7+8+9 = 1
  783. +1 2+3 4+5-6 7+8+9 = 1
  784.  1+2+3-4-5-6-7+8+9 = 1
  785. +1+2+3-4-5-6-7+8+9 = 1
  786. -1+2-3+4-5-6-7+8+9 = 1
  787.  1-2-3-4+5-6-7+8+9 = 1
  788. +1-2-3-4+5-6-7+8+9 = 1
  789. -1-2-3-4-5+6-7+8+9 = 1
  790. -1-2 3+4+5+6-7+8+9 = 1
  791.  1-2+3 4-5 6+7+8+9 = 1
  792. +1-2+3 4-5 6+7+8+9 = 1
  793.  1 2-3 4+5-6+7+8+9 = 1
  794. +1 2-3 4+5-6+7+8+9 = 1
  795. Total solutions  = 69 (26 of which have a leading "+", which is redundant)
  796.  
  797. 69/19683 = 0.35 %
  798.  
  799. for those who care (it's not very elegant but it did the trick):
  800.  
  801. #include <stdio.h>
  802. #include <math.h>
  803.  
  804. main (argc,argv)
  805.      int argc;
  806.      char *argv[];
  807. {
  808.   int sresult, result, operator[10],thisop;
  809.   char buf[256],ops[3];
  810.   int i,j,tot=0,temp;
  811.   
  812.   ops[0] = ' ';
  813.   ops[1] = '-';
  814.   ops[2] = '+';
  815.  
  816.   for (i=1; i<10; i++) operator[i] = 0;
  817.   
  818.   for (j=0; j < 19683; j++) {
  819.     result = 0;
  820.     sresult = 0;
  821.     thisop = 1;
  822.     for (i=1; i<10; i++) {
  823.       switch (operator[i]) {
  824.       case 0:
  825.     sresult = sresult * 10 + i;
  826.     break;
  827.       case 1:
  828.     result = result + sresult * thisop;
  829.     sresult = i;
  830.     thisop = -1;
  831.     break;
  832.       case 2:
  833.     result = result + sresult * thisop;
  834.     sresult = i;
  835.     thisop = 1;
  836.     break;
  837.       }
  838.     }
  839.   
  840.     result  = result + sresult * thisop;
  841.     if (result == 1) {
  842.       tot++;
  843.       for  (i=1;i<10;i++) 
  844.     printf("%c%d",ops[operator[i]],i);
  845.       printf(" = %d\n",result);
  846.     }
  847.     temp = 0;
  848.     operator[1] += 1;
  849.     for (i=1;i<10;i++) {
  850.       operator[i] += temp;
  851.       if (operator[i] > 2) { operator[i] = 0; temp = 1;}
  852.       else temp = 0;
  853.     }
  854.   
  855.   }
  856.   
  857.   printf("Total solutions  = %d\n" , tot);
  858. }
  859.  
  860. cwren@media.mit.edu (Christopher Wren)
  861.  
  862. ==> arithmetic/digits/equations/1992.p <==
  863. 1 = -1+9-9+2.  Extend this list to 2 through 100 on the left side of
  864. the equals sign.
  865.  
  866. ==> arithmetic/digits/equations/1992.s <==
  867. 1 = -1+9-9+2
  868. 2 = 1*9-9+2
  869. 3 = 1+9-9+2
  870. 4 = 1+9/9+2
  871. 5 = 1+9-sqrt(9)-2
  872. 6 = 1^9+sqrt(9)+2
  873. 7 = -1+sqrt(9)+sqrt(9)+2
  874. 8 = 19-9-2
  875. 9 = (1/9)*9^2
  876. 10= 1+(9+9)/2
  877. 11= 1+9+sqrt(9)-2
  878. 12= 19-9+2
  879. 13= (1+sqrt(9))!-9-2
  880. 14= 1+9+sqrt(9)!-2
  881. 15= -1+9+9-2
  882. 16= -1+9+sqrt(9)!+2
  883. 17= 1+9+9-2
  884. 18= 1+9+sqrt(9)!+2
  885. 19= -1+9+9+2
  886. 20= (19-9)*2
  887. 21= 1+9+9+2
  888. 22= (-1+sqrt(9))*(9-2)
  889. 23= (1+sqrt(9))!-sqrt(9)+2
  890. 24= -1+9*sqrt(9)-2
  891. 25= 1*9*sqrt(9)-2
  892. 26= 19+9-2
  893. 27= 1*9+9*2
  894. 28= 1+9+9*2
  895. 29= 1*9*sqrt(9)+2
  896. 30= 19+9+2
  897. 31= (1+sqrt(9))!+9-2
  898. 32= -1+sqrt(9)*(9+2)
  899. 33= 1*sqrt(9)*(9+2)
  900. 34= (-1+9+9)*2
  901. 35= -1+(9+9)*2
  902. 36= 1^9*sqrt(9)!^2
  903. 37= 19+9*2
  904. 38= 1*sqrt(9)!*sqrt(9)!+2
  905. 39= 1+sqrt(9)!*sqrt(9)!+2
  906. 40= (1+sqrt(9)!)*sqrt(9)!-2
  907. 41= -1+sqrt(9)!*(9-2)
  908. 42= (1+sqrt(9))!+9*2
  909. 43= 1+sqrt(9)!*(9-2)
  910. 44= -1+9*(sqrt(9)+2)
  911. 45= 1*9*(sqrt(9)+2)
  912. 46= 1+9*(sqrt(9)+2)
  913. 47= (-1+sqrt(9)!)*9+2
  914. 48= 1*sqrt(9)!*(sqrt(9)!+2)
  915. 49= (1+sqrt(9)!)*(9-2)
  916. 50= (-1+9)*sqrt(9)!+2
  917. 51= -1+9*sqrt(9)!-2
  918. 52= 1*9*sqrt(9)!-2
  919. 53= -1+9*sqrt(9)*2
  920. 54= 1*9*sqrt(9)*2
  921. 55= 1+9*sqrt(9)*2
  922. 56= 1*9*sqrt(9)!+2
  923. 57= 1+9*sqrt(9)!+2
  924. 58= (1+9)*sqrt(9)!-2
  925. 59= 19*sqrt(9)+2
  926. 60= (1+9)*sqrt(9)*2
  927. 61= (1+sqrt(9)!)*9-2
  928. 62= -1+9*(9-2)
  929. 63= 1*9*(9-2)
  930. 64= 1+9*(9-2)
  931. 65= (1+sqrt(9)!)*9+2
  932. 66= 1*sqrt(9)!*(9+2)
  933. 67= 1+sqrt(9)!*(9+2)
  934. 68= -(1+sqrt(9))!+92
  935. 69= (1+sqrt(9))!+(9/.2)
  936. 70= (1+9)*(9-2)
  937. 71= -1-9+9^2
  938. 72= (1+sqrt(9))*9*2
  939. 73= -19+92
  940. 74= (-1+9)*9+2
  941. 75= -1*sqrt(9)!+9^2
  942. 76= 1-sqrt(9)!+9^2
  943. 77= (1+sqrt(9)!)*(9+2)
  944. 78= -1+9*9-2
  945. 79= 1*9*9-2
  946. 80= 1+9*9-2
  947. 81= 1*9*sqrt(9)^2
  948. 82= -1+9*9+2
  949. 83= 1*9*9+2
  950. 84= 1+9*9+2
  951. 85= -1-sqrt(9)!+92
  952. 86= -1*sqrt(9)!+92
  953. 87= 1-sqrt(9)!+92
  954. 88= (1+9)*9-2
  955. 89= -1*sqrt(9)+92
  956. 90= 1-sqrt(9)+92
  957. 91= -1^9+92
  958. 92= (1+9)*9+2
  959. 93= 1^9+92
  960. 94= -1+sqrt(9)+92
  961. 95= 19*(sqrt(9)+2)
  962. 96= -1+99-2
  963. 97= 1*99-2
  964. 98= 1+99-2
  965. 99= 1*9*(9+2)
  966. 100= -1+99+2
  967.  
  968. ==> arithmetic/digits/equations/24.p <==
  969. Form an expression that evaluates to 24 that contains two 3's, two 7's,
  970. and zero or more of the operators +, -, *, and /, and parentheses.  What
  971. about two 4's and two 7's, or three 5's and one 1, or two 3's and two 8's?
  972.  
  973. ==> arithmetic/digits/equations/24.s <==
  974. 7*(3+3/7)
  975. 7*(4-4/7)
  976. 5*(5-1/5)
  977. 8/(3-8/3)
  978.  
  979. ==> arithmetic/digits/equations/383.p <==
  980. Make 383 out of 1,2,25,50,75,100 using +,-,*,/.
  981.  
  982. ==> arithmetic/digits/equations/383.s <==
  983. You can get 383 with ((2+50)/25+1)*100+75.
  984.  
  985. Of course, if you expect / as in C, the above expression is just 375.
  986. But then you can get 383 with (25*50-100)/(1+2).  Pity there's no way
  987. to use the 75.
  988.  
  989. If we had a language that rounded instead of truncating, we could use
  990. ((1+75+100)*50)/(25-2) or (2*75*(25+100))/(50-1).
  991.  
  992. I imagine your problem lies in not dividing things that aren't
  993. divisible.
  994.  
  995. Dan Hoey
  996. Hoey@AIC.NRL.Navy.Mil
  997.  
  998. ==> arithmetic/digits/equations/find.p <==
  999. Write a program for finding expressions built out of given numbers and using
  1000. given operators that evaluate to a given value, or listing all possible values.
  1001.  
  1002. ==> arithmetic/digits/equations/find.s <==
  1003. As set up, it requires recompilation for different sets of numbers;
  1004. it's currently set up for 8,8,3,3; to try in other numbers, stick 'em
  1005. in the 'val' array.  To find all target numbers for which the equation
  1006. is valid, uncomment the 't' loop and 'target = t', and extend the range
  1007. to be checked... you might want to turn off VERBOSE.  I don't bother
  1008. with eliminating symmetries if equal vals are given (like 8 8 3 3), so
  1009. I normally use it like
  1010.  
  1011.     numop 24 | sort | uniq
  1012.  
  1013. As it stands, this gives the output:
  1014.  
  1015. 8 / (3 - (8 / 3)) = 24.0
  1016. 8 / (3 - (8 / 3)) = 24.0
  1017. 8 / (3 - (8 / 3)) = 24.0
  1018. 8 / (3 - (8 / 3)) = 24.0
  1019.  
  1020. As you can see, there are five different kinds of binary trees with
  1021. exactly four leaf nodes.  The program tries all four operators in each
  1022. place, and all four values in each of the leaves, guaranteeing that each
  1023. is used only once... a fairly quick operation.  A small extract from
  1024. 'numop 1' shows the five different shapes of trees:
  1025.  
  1026. ((3 * 8) / 3) / 8 = 1.0
  1027. (3 * (8 / 3)) / 8 = 1.0
  1028. (3 - 3) + (8 / 8) = 1.0
  1029. 3 * ((8 / 3) / 8) = 1.0
  1030. 3 * (8 / (3 * 8)) = 1.0
  1031.  
  1032. Probably FUDGE ought to be set a little lower, for more confidence that
  1033. the equality isn't fortuitous.  Extensions to other binary operators are
  1034. obvious; unary operators and more values are not.  For a more general
  1035. problem I'd go recursive, use exact rational arithmetic, and have a fine
  1036. old time.
  1037.  
  1038. Enjoy...
  1039.  
  1040.     Jim Gillogly <uunet!rand.org!James_Gillogly>
  1041.     21 Wedmath S.R. 1993, 10:58
  1042. ----------------------------------------------------------------
  1043.  
  1044. /* numop: using elementary operations on 4 numbers, find a
  1045.  * desired result; e.g. 24.
  1046.  *
  1047.  * Don't worry about symmetries resulting in multiple correct answers.
  1048.  *
  1049.  * 11 Aug 93, SCRYER
  1050.  */
  1051.  
  1052. #include <stdio.h>
  1053.  
  1054. #define VERBOSE
  1055.  
  1056.  
  1057. #define MUL 0
  1058. #define DIV 1
  1059. #define ADD 2
  1060. #define SUB 3
  1061.  
  1062. #define FUDGE 0.01
  1063.  
  1064. float val[4] = {8, 8, 3, 3};
  1065. float eval(), atof(), fabs();
  1066. char nameop();
  1067.  
  1068. int divzero;
  1069.  
  1070. main(argc, argv)
  1071. int argc;
  1072. char *argv[];
  1073. {
  1074.     int op1, op2, op3;
  1075.     int iv1, iv2, iv3, iv4;
  1076.     int used[4];
  1077.     int i;
  1078.     float target;
  1079.     float e1, e2, e3;
  1080.     int t, winner;
  1081.  
  1082.     if (argc != 2)
  1083.     {
  1084.     fprintf(stderr, "Usage: numop <target>\n");
  1085.     exit(1);
  1086.     }
  1087.     target = atof(argv[1]);
  1088.  
  1089.  
  1090. /* for (t = -1000; t < 1000; t++) */
  1091.  {
  1092. /*    target = t;*/
  1093.     winner = 0;
  1094.  
  1095.     for (i = 0; i < 4; i++) used[i] = 0;
  1096.  
  1097.     for (op1 = 0; op1 < 4; op1++)
  1098.     for (op2 = 0; op2 < 4; op2++)
  1099.         for (op3 = 0; op3 < 4; op3++)
  1100.         for (iv1 = 0; iv1 < 4; iv1++)
  1101.         {
  1102.             used[iv1] = 1;
  1103.             for (iv2 = 0; iv2 < 4; iv2++)
  1104.             {
  1105.             if (used[iv2]) continue;
  1106.             used[iv2] = 1;
  1107.             for (iv3 = 0; iv3 < 4; iv3++)
  1108.             {
  1109.                 if (used[iv3]) continue;
  1110.                 used[iv3] = 1;
  1111.                 for (iv4 = 0; iv4 < 4; iv4++)
  1112.                 {
  1113.                 if (used[iv4]) continue;
  1114.  
  1115.                 /* Case 1 */
  1116.                 divzero = 0;
  1117.                 e3 = eval(op3, val[iv3], val[iv4]);
  1118.                 e2 = eval(op2, val[iv1], val[iv2]);
  1119.                 e1 = eval(op1, e2, e3);                         /* (u + v) * (w - x) */
  1120.                 if (fabs(e1 - target) < FUDGE && ! divzero)
  1121. #ifdef VERBOSE
  1122.                     printf("(%.0f %c %.0f) %c (%.0f %c %.0f) = %.1f\n",
  1123.                     val[iv1], nameop(op2), val[iv2], nameop(op1),
  1124.                     val[iv3], nameop(op3), val[iv4], e1);
  1125. #else
  1126.                     winner = 1;
  1127. #endif
  1128.                 /* Case 2 */
  1129.                 divzero = 0;
  1130.                 e3 = eval(op3, val[iv1], val[iv2]);
  1131.                 e2 = eval(op2, e3, val[iv3]);
  1132.                 e1 = eval(op1, e2, val[iv4]);                   /* ((u + v) * w) - x */
  1133.                 if (fabs(e1 - target) < FUDGE && ! divzero)
  1134. #ifdef VERBOSE
  1135.                     printf("((%.0f %c %.0f) %c %.0f) %c %.0f = %.1f\n",
  1136.                     val[iv1], nameop(op3), val[iv2], nameop(op2), val[iv3], nameop(op1), val[iv4], e1);
  1137. #else
  1138.                     winner = 1;
  1139. #endif
  1140.  
  1141.                 /* Case 3 */
  1142.                 divzero = 0;
  1143.                 e3 = eval(op3, val[iv2], val[iv3]);
  1144.                 e2 = eval(op2, val[iv1], e3);
  1145.                 e1 = eval(op1, e2, val[iv4]);                   /* (u + (v * w)) - x */
  1146.                 if (fabs(e1 - target) < FUDGE && ! divzero)
  1147. #ifdef VERBOSE
  1148.                     printf("(%.0f %c (%.0f %c %.0f)) %c %.0f = %.1f\n",
  1149.                     val[iv1], nameop(op2), val[iv2], nameop(op3), val[iv3],
  1150.                     nameop(op1), val[iv4], e1);
  1151. #else
  1152.                     winner = 1;
  1153. #endif
  1154.  
  1155.                 /* Case 4 */
  1156.                 divzero = 0;
  1157.                 e3 = eval(op3, val[iv2], val[iv3]);
  1158.                 e2 = eval(op2, e3, val[iv4]);
  1159.                 e1 = eval(op1, val[iv1], e2);                   /* u + ((v * w) - x) */
  1160.                 if (fabs(e1 - target) < FUDGE && ! divzero)
  1161. #ifdef VERBOSE
  1162.                     printf("%.0f %c ((%.0f %c %.0f) %c %.0f) = %.1f\n",
  1163.                     val[iv1], nameop(op1), val[iv2], nameop(op3), val[iv3],
  1164.                     nameop(op2), val[iv4], e1);
  1165. #else
  1166.                     winner = 1;
  1167. #endif
  1168.  
  1169.                 /* Case 5 */                                    /* u + (v * (w - x)) */
  1170.                 divzero = 0;
  1171.                 e3 = eval(op3, val[iv3], val[iv4]);
  1172.                 e2 = eval(op2, val[iv2], e3);
  1173.                 e1 = eval(op1, val[iv1], e2);
  1174.                 if (fabs(e1 - target) < FUDGE && ! divzero)
  1175. #ifdef VERBOSE
  1176.                     printf("%.0f %c (%.0f %c (%.0f %c %.0f)) = %.1f\n",
  1177.                     val[iv1], nameop(op1), val[iv2], nameop(op2), val[iv3],
  1178.                     nameop(op3), val[iv4], e1);
  1179. #else
  1180.                     winner = 1;
  1181. #endif
  1182.  
  1183.                 }
  1184.                 used[iv3] = 0;
  1185.             }
  1186.             used[iv2] = 0;
  1187.             }
  1188.             used[iv1] = 0;
  1189.         }
  1190. #ifndef VERBOSE
  1191.      if (winner) printf("%d\n", t), fflush(stdout);
  1192. #endif
  1193.   }
  1194. }
  1195.  
  1196. char nameop(op)
  1197. int op;
  1198. {
  1199.     switch(op)
  1200.     {
  1201.     case MUL: return '*';
  1202.     case DIV: return '/';
  1203.     case ADD: return '+';
  1204.     case SUB: return '-';
  1205.     }
  1206.     return '?';
  1207. }
  1208.  
  1209. float eval(op, val1, val2)
  1210. int op;
  1211. float val1, val2;
  1212. {
  1213.     switch(op)
  1214.     {
  1215.     case MUL: return val1 * val2;
  1216.     case DIV:
  1217.         if (val2 == 0.)
  1218.         {
  1219.             divzero = 1;
  1220. #ifdef EXTREMELYVERBOSE
  1221.             fprintf(stderr, "Division by zero.\n");
  1222. #endif
  1223.         }
  1224.         return val2 == 0.? 0. : val1 / val2;
  1225.     case ADD: return val1 + val2;
  1226.     case SUB: return val1 - val2;
  1227.     }
  1228.     return 0.;
  1229. }
  1230.  
  1231.  
  1232.  
  1233. ==> arithmetic/digits/extreme.products.p <==
  1234. What are the extremal products of three three-digit numbers using digits 1-9?
  1235.  
  1236. ==> arithmetic/digits/extreme.products.s <==
  1237. There is a simple procedure which applies to these types of problems (and
  1238. which can be proven with help from the arithmetic-geometric inequality).
  1239.  
  1240. For the first part we use the "first large then equal" procedure.
  1241. This means that are three numbers will be 7**, 8**, and 9**.  Now
  1242. the digits 4,5,6 get distributed so as to make our three number as
  1243. close to each other as possible, i.e. 76*, 85*, 94*.  The same goes
  1244. for the remaining three digits, and we get 763, 852, 941.
  1245.  
  1246. For the second part we use the "first small then different" procedure.
  1247. Our three numbers will be of the form 1**, 2**, 3**.  We now place
  1248. the three digits so as to make our three numbers as unequal as possible;
  1249. this gives 14*, 25*, 36*.  Finishing, we get 147, 258, 369.
  1250.  
  1251. Now, *prove* that these procedures work for generalizations of this
  1252. problem.
  1253.  
  1254. ==> arithmetic/digits/labels.p <==
  1255. You have an arbitrary number of model kits (which you assemble for
  1256. fun and profit).  Each kit comes with twenty (20) stickers, two of which
  1257. are labeled "0", two are labeled "1", ..., two are labeled "9".
  1258. You decide to stick a serial number on each model you assemble starting
  1259. with one.  What is the first number you cannot stick.  You may stockpile
  1260. unused numbers on already assembled models, but you may not crack open
  1261. a new model to get at its stickers.  You complete assembling the current
  1262. model before starting the next.
  1263.  
  1264. ==> arithmetic/digits/labels.s <==
  1265. The method I used for this problem involved first coming up with a
  1266. formula that says how many times a digit has been used in all n models.
  1267.  
  1268. n = k*10^i + m for some k,m with 0 <k <10, m < 10^i
  1269. f(d,n) = (number of d's used getting to k*10^i from digits 0 to (i-1)) +
  1270.     (number of d's used by #'s 10^i to n from digit i) + f(d,m)
  1271. f(d,n) = i*k*10^(i-1) + (if (d < k) 10^i else if (d == k) m+1 else 0) + f(d,m)
  1272.  
  1273. This doesn't count 0's, which should be ok as they are not used as often
  1274. as other digits.  From the formula, it is clear that f(1,n) is never
  1275. less than f(d,n) for 1<d<10.
  1276. So I just calculated f(1,n) for various n (with some help from bc).
  1277.  
  1278. I quickly discovered that for n = 2*10^15, f(1,n) = 2*n.  After further
  1279. trials I determined that for n = 1999919999999981, f(1,n) = 2*n + 1. 
  1280. This appears to be the smallest n with f(1,n) > 2*n.
  1281.  
  1282. ==> arithmetic/digits/least.significant/factorial.p <==
  1283. What is the least significant non-zero digit in the decimal expansion of n!?
  1284.  
  1285. ==> arithmetic/digits/least.significant/factorial.s <==
  1286. Reduce mod 10 the numbers 2..n and then cancel out the
  1287. required factors of 10. The final step then involves
  1288. computing 2^i*3^j*7^k mod 10 for suitable i,j and k. 
  1289.  
  1290. A small program that performs this calculation is appended. Like the
  1291. other solutions, it takes O(log n) arithmetic operations.
  1292.  
  1293. -kym
  1294. ===
  1295.  
  1296. #include<stdio.h>
  1297. #include<assert.h>
  1298.  
  1299. int    p[6][4]={
  1300.     /*2*/    2,    4,    8,    6,
  1301.     /*3*/    3,    9,    7,    1,
  1302.     /*4*/    4,    6,    4,    6,
  1303.     /*5*/    5,    5,    5,    5,
  1304.     /*6*/    6,    6,    6,    6,
  1305.     /*7*/    7,    9,    3,    1,
  1306.     };
  1307.  
  1308. main(){
  1309.     int    i;
  1310.     int n;
  1311.  
  1312.     for(n=2;n<1000;n++){
  1313.         i=lsdfact(n);
  1314.         printf("%d\n",i);
  1315.         }
  1316.  
  1317.     exit(0);
  1318.     }
  1319.  
  1320. lsdfact(n){
  1321.     int    a[10];
  1322.     int    i;
  1323.     int    n5;
  1324.     int    tmp;
  1325.  
  1326.     for(i=0;i<=9;i++)a[i]=alpha(i,n);
  1327.  
  1328.     n5=0;
  1329. /* NOTE: order is important in following */
  1330. l5:;
  1331.     while(tmp=a[5]){    /* cancel factors of 5 */
  1332.         n5+=tmp;
  1333.         a[1]+=(tmp+4)/5;
  1334.         a[3]+=(tmp+3)/5;
  1335.         a[5]=(tmp+2)/5;
  1336.         a[7]+=(tmp+1)/5;
  1337.         a[9]+=(tmp+0)/5;
  1338.         }
  1339. l10:;
  1340.     if(tmp=a[0]){
  1341.         a[0]=0;    /* cancel all factors of 10 */
  1342.         for(i=0;i<=9;i++)a[i]+=alpha(i,tmp);
  1343.         }
  1344.     if(a[5]) goto l5;
  1345.     if(a[0]) goto l10;
  1346.  
  1347. /* n5 == number of 5's cancelled; 
  1348.    must now cancel same number of factors of 2 */
  1349.     i=ipow(2,a[2]+2*a[4]+a[6]+3*a[8]-n5)*
  1350.         ipow(3,a[3]+a[6]+2*a[9])*
  1351.         ipow(7,a[7]);
  1352.     assert(i%10);    /* must not be zero */
  1353.     return    i%10;
  1354.     }
  1355.  
  1356. alpha(d,n){
  1357. /* number of decimal numbers in [1,n] ending in digit d */
  1358.     int tmp;
  1359.     tmp=(n+10-d)/10;
  1360.     if(d==0)tmp--;    /* forget 0 */
  1361.     return tmp;
  1362.     }
  1363.  
  1364. ipow(x,y){
  1365. /* x^y mod 10 */
  1366.     if(y==0) return 1;
  1367.     if(y==1) return x;
  1368.     return p[x-2][(y-1)%4];
  1369.     }
  1370.  
  1371.  
  1372.  
  1373.  
  1374. ==> arithmetic/digits/least.significant/tower.of.power.p <==
  1375. What are the least significant digits of 9^(8^(7^(6^(5^(4^(3^(2^1))))))) ?
  1376.  
  1377. ==> arithmetic/digits/least.significant/tower.of.power.s <==
  1378. 9^11 = 9 (mod 100), so we need to find 8^...^1 (mod 10).
  1379. 8^5 = 8 (mod 10), so we need to find 7^...^1 (mod 4).
  1380. 7^3 = 7 (mod 4), so we need to find 6^...^1 (mod 2), but
  1381. this is clearly 0, so 7^...^1 = 1 (mod 4) ==>
  1382. 8^...^1 = 8 (mod 10) ==> 9^...^1 = 9^8 (mod 100) = 21 (mod 100).
  1383.  
  1384. ==> arithmetic/digits/most.significant/googol.p <==
  1385. What digits does googol! start with?
  1386.  
  1387. ==> arithmetic/digits/most.significant/googol.s <==
  1388. I'm not sure how to calculate the first googol of digits of log10(e), but
  1389. here's the first 150(approximately) of them...
  1390.  
  1391. 0.43429448190325182765112891891660508229439700580366656611445378316586464920
  1392. 8870774729224949338431748318706106744766303733641679287158963906569221064663
  1393.  
  1394. We need to deal with the digits immediately after the decimal point in
  1395. googol*log10(e), which are  .187061
  1396.  
  1397. frac[log(googol!)] = frac[halflog2pi + 50 + googol(100-log10(e))]
  1398.  = frac{halflog2pi + frac[googol(100-log10(e))]}
  1399.  = frac[.399090 + (1- .187061)]
  1400.  = .212029
  1401.  
  1402. 10 ** .212029 = 1.629405
  1403.  
  1404. Which means that googol! starts with 1629
  1405.  
  1406. ==> arithmetic/digits/most.significant/powers.p <==
  1407. What is the probability that 2^N begins with the digits 603245?
  1408.  
  1409. ==> arithmetic/digits/most.significant/powers.s <==
  1410. 2^N begins with 603245 iff 603246*10^m > 2^N >= 603245*10^m for some
  1411. positive integer m ==> m+log(603246) > N*log(2) >= m+log(603245);
  1412. so 2^N begins with 603245 iff frac(log(603246)) > frac(N*log(2))
  1413. >= frac(log(603245)).  If we are using natural density then N*log(2)
  1414. is uniformly distributed mod 1 since log(2) is irrational, hence the
  1415. probability is frac(log(603246)) - frac(log(603245)) =
  1416. frac(log(603246)-log(603245)) = frac(log(603246/603245)).
  1417.  
  1418. A neat observation is that since it is known p_n*c, where p_n is the
  1419. nth prime and c is irrational, is uniformly distributed mod 1, we get
  1420. the same answer if we replace 2^N with 2^{p_n}.
  1421. -- 
  1422. Chris Long, 265 Old York Rd., Bridgewater, NJ  08807-2618
  1423.  
  1424. ==> arithmetic/digits/nine.digits.p <==
  1425. Form a number using 0-9 once with its first n digits divisible by n.
  1426.  
  1427. ==> arithmetic/digits/nine.digits.s <==
  1428. First, reduce the sample set. For each digit of ABCDEFGHI, such that the last
  1429. digit, (current digit), is the same as a multiple of N :
  1430.  
  1431. A: Any number 1-9
  1432. B: Even numbers 2,4,6,8 (divisible by 2).
  1433. C: Any number 1-9 (21,12,3,24,15,6,27,18,9).
  1434. D: Even numbers 2,4,6,8 (divisible by 4, every other even).
  1435. E: 5 (divisible by 5 and 0 not allowed).
  1436. F: Even numbers (12,24,6,18)
  1437. G: Any number 1-9 (21,42,63,14,35,56,7,28,49).
  1438. H: Even numbers (32,24,16,8)
  1439. I: Any number 1-9 (81,72,63,54,45,36,27,18,9)
  1440.  
  1441. Since E must be 5, I can eliminate it everywhere else.
  1442. Since I will use up all the even digits, (2,4,6,8) filling in those spots
  1443.    that must be even. Any number becomes all odds, except 5.
  1444.  
  1445. A: 1,3,7,9
  1446. B: 2,4,6,8
  1447. C: 1,3,7,9
  1448. D: 2,4,6,8
  1449. E: 5
  1450. F: 2,4,6,8
  1451. G: 1,3,7,9
  1452. H: 2,4,6,8
  1453. I: 1,3,7,9
  1454.  
  1455. We have that 2C+D=0 (mod 4), and since C is odd,
  1456. this implies that D is 2 or 6; similarly we find that H is 2 or 6 ==>
  1457. {B,F} = {4,8}.  D+5+F=0 (mod 3) ==> if D=2 then F=8, if D=6 then F=4.
  1458.  
  1459. We have two cases.
  1460.  
  1461. Assume our number is of the form A4C258G6I0.  Now the case n=8 ==>
  1462. G=1,9; case n=3 ==> A+1+C=0 (mod 3) ==> {A,C}={1,7} ==> G=9, I=3.
  1463. The two numbers remaining fail for n=7.
  1464.  
  1465. Assume our number is of the form A8C654G2I0.  The case n=8 ==> G=3,7.
  1466. If G=3, we need to check to see which of 1896543, 9816543, 7896543, 
  1467. and 9876543 are divisible by 7; none are.
  1468.  
  1469. If G=7, we need to check to see which of 1896547, 9816547, 1836547,
  1470. and 3816547 are divisible by 7; only the last one is, which yields
  1471. the solution 3816547290.
  1472.  
  1473. ==> arithmetic/digits/palindrome.p <==
  1474. Does the series formed by adding a number to its reversal always end in
  1475. a palindrome?
  1476.  
  1477. ==> arithmetic/digits/palindrome.s <==
  1478. This is not known.
  1479.  
  1480. If you start with 196, after 9480000 iterations you get a 3924257-digit
  1481. non-palindromic number.  However, there is no known proof that you will
  1482. never get a palindrome.
  1483.  
  1484. The statement is provably false for binary numbers. Roland Sprague has
  1485. shown that 10110 starts a series that never goes palindromic.
  1486.  
  1487. ==> arithmetic/digits/palintiples.p <==
  1488. Find all numbers that are multiples of their reversals.
  1489.  
  1490. ==> arithmetic/digits/palintiples.s <==
  1491. We are asked to find numbers that are integer multiples of their
  1492. reversals, which I call palintiples.  Of course, all the palindromic
  1493. numbers are a trivial example, but if we disregard the unit multiples,
  1494. the field is narrowed considerably.
  1495.  
  1496. Rouse Ball (_Mathematical_recreations_and_essays_) originated the
  1497. problem, and G. H. Hardy (_A_mathematician's_apology_) used the result
  1498. that 9801 and 8712 are the only four-digit palintiples as an example
  1499. of a theorem that is not ``serious''.  Martin Beech (_The_mathema-
  1500. tical_gazette_, Vol 74, #467, pp 50-51, March '90) observed that
  1501. 989*01 and 879*12 are palintiples, an observation he ``confirmed'' on
  1502. a hand calculator, and conjectured that these are all that exist.
  1503.  
  1504. I confirm that Beech's numbers are palintiples, I will show that they
  1505. are not all of the palintiples.  I will show that the palintiples do
  1506. not form a regular language.  And then I will prove that I have found
  1507. all the palintiples, by describing the them with a generalized form
  1508. of regular expression.  The results become more interesting in other
  1509. bases.
  1510.  
  1511. First, I have a more reasonable method of confirming that these
  1512. numbers are palintiples:
  1513.  
  1514.     Proof:  First, letting "9*" and "0*" refer an arbitrary string of
  1515.     nines and a string of zeroes of the same length, I note that
  1516.  
  1517.         879*12 = 879*00 + 12 = (880*00 - 100) + 12 = 880*00 - 88
  1518.         219*78 = 219*00 + 78 = (220*00 - 100) + 78 = 220*00 - 22
  1519.  
  1520.         989*01 = 989*00 +  1 = (990*00 - 100) +  1 = 990*00 - 99
  1521.         109*89 = 109*00 + 89 = (110*00 - 100) + 89 = 110*00 - 11
  1522.  
  1523.     It is obvious that 4x(220*00 - 22) = 880*00 - 88 and that
  1524.     9x(110*00 - 11) = 990*00 - 99.  QED.
  1525.  
  1526. Now, to show that these palintiples are not all that exist, let us
  1527. take the (infinite) language L[4] = (879*12 + 0*), and let Pal(L[4])
  1528. refer to the set of palindromes over the alphabet L[4].  It is
  1529. immediate that the numbers in Pal(L[4]) are palintiples.  For
  1530. instance,
  1531.  
  1532.           8712 000 87912 879999912 879999912 87912 000 8712
  1533.     = 4 x 2178 000 21978 219999978 219999978 21978 000 2178
  1534.  
  1535. (where I have inserted spaces to enhance readability) is a palintiple.
  1536. Similarly, taking L[9] = (989*01 + 0*), the numbers in Pal(L[9]) are
  1537. palintiples.  We exclude numbers starting with zeroes.
  1538.  
  1539. The reason these do not form a regular language is that the
  1540. sub-palintiples on the left end of the number must be the same (in
  1541. reverse order) as the sub-palintiples on the right end of the number:
  1542.  
  1543.          8712 8712 87999912 = 4 x 2178 2178 21999978
  1544.  
  1545. is not a palintiple, because 8712 8712 87999912 is not the reverse of
  1546. 2178 2178 21999978.  The pumping lemma can be used to prove that
  1547. Pal(L[4])+Pal(L[9]) is not a regular language, just as in the familiar
  1548. proof that the palindromes over a non-singleton alphabet do not form a
  1549. regular language.
  1550.  
  1551. Now to characterize all the palintiples, let N be a palintiple,
  1552. N=CxR(N), where R(.) signifies reversal, and C>1 is an integer.  (I
  1553. use "x" for multiplication, to avoid confusion with the Kleene star
  1554. "*", which signifies the concatenated closure.)  If D is a digit of N,
  1555. let D' refer to the corresponding digit of R(N).  Since N=CxR(N),
  1556. D+10T = CxD'+S, where S is the carry in to the position occupied by D'
  1557. when R(N) is multiplied by C, and T is the carry out of that position.
  1558. Similarly, D'+10T'=CxD+S', where S', T' are carries in and out of the
  1559. position occupied by D when R(N) is multiplied by C.
  1560.  
  1561. Since D and D' are so closely related, I will use the symbol D:D' to
  1562. refer to a digit D on the left side of a string with a corresponding
  1563. digit D' on the right side of the string.  More formally, an
  1564. expression "x[1]:y[1] x[2]:y[2] ... x[n]:y[n] w" will refer to a
  1565. string "x[1] x[2] ... x[n] w y[n] ... y[2] y[1]", where the x[i] and
  1566. y[i] are digits and w is a string of zero or one digits.  So 989901
  1567. may be written as 9:1 8:0 9:9 and 87912 may be written as 8:2 7:1 9.
  1568. Thus Pal(L[4])+Pal(L[9]) (omitting numbers with leading zeroes) can be
  1569. represented as
  1570.  
  1571.             (8:2 7:1 9:9* 1:7 2:8 0:0*)*
  1572.               (0:0* + 0 + 8:2 7:1 ( 9:9* + 9:9* 9))
  1573.           + (9:1 8:0 9:9* 0:8 1:9 0:0*)*
  1574.               (0:0* + 0 + 9:1 8:0 ( 9:9* + 9:9* 9)).      (1)
  1575.  
  1576. For each pair of digits D:D', there are a very limited--and often
  1577. empty--set of quadruples S,T,S',T' of digits that satisfy the
  1578. equations
  1579.  
  1580.                     D +10T =CxD'+S
  1581.                     D'+10T'=CxD +S',                      (2)
  1582.  
  1583. yet such a quadruple must exist for "D:D'" to appear in a palintiple
  1584. with multiplier C.  Furthermore, the S and T' of one D:D' must be T
  1585. and S', respectively, of the next pair of digits that appear.  This
  1586. enables us to construct a finite state machine to recognize those
  1587. palintiples.  The states [X#Y] refer to a pair of carries in D and D',
  1588. and we allow a transition from state [T#S'] to state [S#T'] on input
  1589. symbol D:D' exactly when equations (2) are satisfied.  Special
  1590. transitions for a single-digit input symbol (the central digit of
  1591. odd-length palintiples) and the criteria for the initial and the
  1592. accepting states are left as exercises.  The finite state machines
  1593. thus formed are
  1594.  
  1595.    State         Symbol  New     Symbol  New      Symbol   New
  1596.         Accept?         State           State             State
  1597.  
  1598. --> [0#0]  Y       8:2  [0#3]      0:0  [0#0]         0   [A]
  1599.     [0#3]  N       7:1  [3#3]
  1600.     [3#3]  Y       1:7  [3#0]      9:9  [3#3]         9   [A]
  1601.     [3#0]  N       2:8  [0#0]
  1602.      [A]   Y
  1603.  
  1604. for constant C=4, and
  1605.  
  1606.    State         Symbol  New     Symbol  New      Symbol   New
  1607.         Accept?         State           State             State
  1608.  
  1609. --> [0#0]  Y       1:9  [0#8]      0:0  [0#0]         0   [A]
  1610.     [0#8]  N       8:0  [8#8]
  1611.     [8#8]  Y       0:8  [8#0]      9:9  [8#8]         9   [A]
  1612.     [8#0]  N       9:1  [0#0]
  1613.      [A]   Y
  1614.  
  1615. for constant C=9, and the finite state machines for other constants
  1616. accept only strings of zeroes.  It is not hard to verify that the
  1617. proposed regular expression (1) represents the union of the languages
  1618. accepted by these machines, omitting the empty string and strings
  1619. beginning with zero.
  1620.  
  1621. I have written a computer program that constructs finite state
  1622. machines for recognizing palintiples for various bases and constants.
  1623. I found that base 10 is actually an unusually boring base for this
  1624. problem.  For instance, the machine for base 8, constant C=5 is
  1625.  
  1626.    State         Symbol  New     Symbol  New      Symbol  New
  1627.         Accept?         State           State            State
  1628.  
  1629. --> [0#0]  Y       0:0  [0#0]      5:1  [0#3]         0  [A]
  1630.     [0#3]  N       1:0  [1#1]      6:1  [1#4]
  1631.     [1#1]  Y       0:1  [3#0]      5:2  [3#3]
  1632.     [3#0]  N       1:5  [0#0]      6:6  [0#3]         6  [A]
  1633.     [3#3]  Y       2:5  [1#1]      7:6  [1#4]
  1634.     [1#4]  N       1:1  [4#1]      6:2  [4#4]         1  [A]
  1635.     [4#4]  Y       2:6  [4#1]      7:7  [4#4]         7  [A]
  1636.     [4#1]  N       1:6  [3#0]      6:7  [3#3]
  1637.      [A]   Y
  1638.  
  1639. for which I invite masochists to write the regular expression.  If
  1640. anyone wants more, I should remark that the base 29 machine for
  1641. constant C=18 has 71 states!
  1642.  
  1643. By the way, I did not find any way of predicting the size or form of
  1644. the machines for the various bases, except that the machines for C=B-1
  1645. all seem to be isomorphic to each other.  If anyone investigates the
  1646. general behavior, I would be most happy to hear about it.
  1647.  
  1648. Dan Hoey
  1649. Hoey@AIC.NRL.Navy.Mil
  1650. May, 1992
  1651. [ A preliminary version of this message appeared in April, 1991. ]
  1652. ================================================================
  1653. Dan
  1654.  
  1655.  
  1656.  
  1657. ==> arithmetic/digits/power.two.p <==
  1658. Prove that for any 9-digit number (base 10) there is an integral power
  1659. of 2 whose first 9 digits are that number.
  1660.  
  1661. ==> arithmetic/digits/power.two.s <==
  1662. Let v = log to base 10 of 2.
  1663. Then v is irrational.
  1664.  
  1665. Let w = log to base 10 of these 9 digits.
  1666.  
  1667. Since v is irrational, given epsilon > 0, there exists some natural number 
  1668. n such that
  1669.  
  1670.    {w} < {nv} < {w} + epsilon
  1671.  
  1672. ({x} is the fractional part of x.)  Let us pick n for when 
  1673.  
  1674.    epsilon = log 1.00000000000000000000001.
  1675.  
  1676. Then 2^n does the job.
  1677.  
  1678. ==> arithmetic/digits/prime/101.p <==
  1679. How many primes are in the sequence 101, 10101, 1010101, ...?
  1680.  
  1681. ==> arithmetic/digits/prime/101.s <==
  1682. Note that the sequence
  1683. 101 , 10101, 1010101, ....
  1684. can be viewed as 
  1685. 100**1 +1, 100**2 + 100**1 + 1, 100**3 + 100**2 + 100**1 +1 ....
  1686. that is, 
  1687. the k-th term in the sequence is 
  1688. 100**k + 100**(k-1) + 100**(k-2) + ...+ 100**(1) + 1
  1689. = (100)**(k+1) - 1
  1690.   ----------------
  1691.     11 * 9
  1692. = (10)**(2k+2) - 1
  1693.   ----------------
  1694.     11 * 9
  1695. = ((10)**(k+1) - 1)*((10)**(k+1) +1)
  1696.    ---------------------------------
  1697.        11*9
  1698. thus either 11 and 9 divide the numerator. Either they both divide the
  1699. same factor in the numerator or different factors in the numerator. In
  1700. any case, after dividing, they leave the numerators as a product of two
  1701. integers.  Only in the case of k = 1, one of the integers is 1. Thus
  1702. there is exactly one prime in the above sequence: 101.
  1703.  
  1704. ==> arithmetic/digits/prime/all.prefix.p <==
  1705. What is the longest prime whose every proper prefix is a prime?
  1706.  
  1707. ==> arithmetic/digits/prime/all.prefix.s <==
  1708. 23399339, 29399999, 37337999, 59393339, 73939133
  1709.  
  1710. ==> arithmetic/digits/prime/change.one.p <==
  1711. What is the smallest number that cannot be made prime by changing a single
  1712. digit?  Are there infinitely many such numbers?
  1713.  
  1714. ==> arithmetic/digits/prime/change.one.s <==
  1715. 200.  Obviously, you would have to change the last digit, but 201, 203,
  1716. 207, and 209 are all composite.  For any smaller number, you can change
  1717. the last digit, and get
  1718. 2,11,23,31,41,53,61,71,83,97,101,113,127,131,149,151,163,173,181, or 191.
  1719.  
  1720. 200+2310n gives an infinite family, because changing the last
  1721. digit to 1 or 7 gives a number divisible by 3; to 3, a number divisible
  1722. by 7; to 9, a number divisible by 11.
  1723.  
  1724. ==> arithmetic/digits/prime/prefix.one.p <==
  1725. 2 is prime, but 12, 22, ..., 92 are not.  Similarly, 5 is prime
  1726. whereas 15, 25, ..., 95 are not.  What is the next prime number
  1727. which is composite when any digit is prefixed?
  1728.  
  1729. ==> arithmetic/digits/prime/prefix.one.s <==
  1730. 149
  1731.  
  1732. ==> arithmetic/digits/reverse.p <==
  1733. Is there an integer that has its digits reversed after dividing it by 2?
  1734.  
  1735. ==> arithmetic/digits/reverse.s <==
  1736. Assume there's such a positive integer x such that x/2=y and y is the
  1737. reverse of x.
  1738.  
  1739. Then x=2y.  Let x = a...b, then y = b...a, and:
  1740.  
  1741.                  b...a   (y)
  1742.            x     2
  1743.                --------
  1744.                  a...b   (x)
  1745.  
  1746. From the last digit b of x, we have b = 2a (mod 10), the possible
  1747. values for b are 2, 4, 6, 8 and hence possible values for (a, b) are
  1748. (1,2), (6,2), (2,4), (7,4), (3,6), (8,6), (4,8), (9,8).
  1749.  
  1750. From the first digit a of x, we have a = 2b or a = 2b+1.  None of the
  1751. above pairs satisfy this condition.  A contradiction.
  1752.  
  1753. Hence there's no such integer.
  1754.  
  1755. ==> arithmetic/digits/rotate.p <==
  1756. Find integers where multiplying them by single digits rotates their digits
  1757. one position, so that the last digit become the first digit.
  1758.  
  1759. ==> arithmetic/digits/rotate.s <==
  1760. 2 105263157894736842
  1761. 3 1034482758620689655172413793
  1762. 4 102564 153846 179487 205128 230769
  1763. 5 142857 102040816326530612244897959183673469387755
  1764. 6 1016949152542372881355932203389830508474576271186440677966
  1765.   1186440677966101694915254237288135593220338983050847457627
  1766.   1355932203389830508474576271186440677966101694915254237288
  1767.   1525423728813559322033898305084745762711864406779661016949
  1768. 7 1014492753623188405797 1159420289855072463768 1304347826086956521739
  1769. 8 1012658227848 1139240506329
  1770. 9 10112359550561797752808988764044943820224719
  1771.  
  1772. In base B, suppose you have an N-digit answer A whose digits are
  1773. rotated when multiplied by K.  If D is the low-order digit of A, we
  1774. have
  1775.  
  1776.     (A-D)/B + D B^(N-1) = K A .
  1777.  
  1778. Solving this for A we have
  1779.  
  1780.         D (B^N - 1)
  1781.     A = ----------- .
  1782.           B K - 1
  1783.  
  1784. In order for A >= B^(N-1) we must have D >= K.  Now we have to find N
  1785. such that B^N-1 is divisible by R=(BK-1)/gcd(BK-1,D).  This always has
  1786. a minimal solution N0(R,B)<R, and the set of all solutions is the set
  1787. of multiples of N0(R,B).  N0(R,B) is the length of the repeating part
  1788. of the fraction 1/R in base B.
  1789.  
  1790. N0(ST,B)=N0(S,B)N0(T,B) when (S,T)=1, and for prime powers, N0(P^X,B)
  1791. divides (P-1)P^(X-1). Determining which divisor is a little more
  1792. complicated but well-known (cf. Hardy & Wright).
  1793.  
  1794. So given B and K, there is one minimal solution for each
  1795. D=K,K+1,...,B-1, and you get all the solutions by taking repetitions
  1796. of the minimal solutions.
  1797.  
  1798. ==> arithmetic/digits/sesqui.p <==
  1799. Find the least number where moving the first digit to the end multiplies by 1.5.
  1800.  
  1801. ==> arithmetic/digits/sesqui.s <==
  1802. Let's represent this number as  a*10^n+b,  where 1<=a<=9 and
  1803. b < 10^n.  Then the condition to be satisfied is:
  1804.  
  1805. 3/2(a*10^n+b) = 10b+a
  1806.  
  1807.   3(a*10^n+b) = 20b+2a
  1808.  
  1809.    3a*10^n+3b = 20b+2a
  1810.  
  1811.   (3*10^n-2)a = 17b
  1812.  
  1813.             b = a*(3*10^n-2)/17
  1814.  
  1815. So we must have 3*10^n-2 = 0 (mod 17) (since a is less than 10, it
  1816. cannot contribute the needed prime 17 to the factorization of 17b).
  1817. (Also, assuming large n, we must have a at most 5 so that b < 10^n will
  1818. be satisfied, but note that we can choose a=1).  Now,
  1819.  
  1820. 3*10^n-2 = 0 (mod 17)
  1821.  
  1822. 3*10^n = 2 (mod 17)
  1823.  
  1824. 10^n = 12 (mod 17)
  1825.  
  1826. A quick check shows that the smallest n which satisfies this is 15
  1827. (the fact that one exists was assured to us because 17 is prime).  So,
  1828. setting n=15 and a=1 (obviously) gives us b=176470588235294, so the
  1829. number we are looking for is
  1830.  
  1831.                         1176470588235294
  1832.  
  1833. and, by the way, we can set a=2 to give us the second smallest such
  1834. number,
  1835.                         2352941176470588
  1836.  
  1837. Other things we can infer about these numbers is that there are 5 of
  1838. them less than 10^16, 5 more less than 10^33, etc.
  1839.  
  1840. ==> arithmetic/digits/squares/change.leading.p <==
  1841. What squares remain squares when their leading digits are incremented?
  1842.  
  1843. ==> arithmetic/digits/squares/change.leading.s <==
  1844. Omitting solutions that are obtained from smaller solutions by
  1845. multiplying by powers of 10, the squares of these numbers satisfy the
  1846. condition:
  1847.  
  1848. 1. (105,145), (3375,4625), (14025,17225), (326625,454625),
  1849.     (10846875,14753125), (43708125,53948125), ...
  1850.  
  1851. 2. (45,55), (144375,175625), (463171875,560828125), ...
  1852.  
  1853. 7. (2824483699753370361328125,2996282391593370361328125), ...
  1854.  
  1855. Here is how to find them. We have (y+x)*(y-x) = 10^n, and so we must have 
  1856. {y+x, y-x} as {5^m*10^a, 2^m*10^b} in some order. It is also necessary (and
  1857. sufficient) that y/x lies in the interval [sqrt(3/2),sqrt(2)], or equivalently
  1858. that (y+x)/(y-x) lies in [3+sqrt(8),5+sqrt(24)] = [5.82842...,9.89897...].
  1859. Thus we need to make (5/2)^m*10^(a-b), or its reciprocal, in this range.
  1860. For each m there is clearly at most one power of 10 that will do. m=2,a=b
  1861. gives (105,145); m=3,b=a+2 gives (3375,4625), and so on.
  1862.  
  1863. There are infinitely many non-equivalent solutions, because log(5/2) / log(10)
  1864. is irrational.
  1865.  
  1866. One can use exactly the same argument to find squares whose initial 2 can 
  1867. be replaced by a 3, of course, except that the range of (y+x)/(y-x) changes.
  1868.  
  1869. ==> arithmetic/digits/squares/length.22.p <==
  1870. Is it possible to form two numbers A and B from 22 digits such that
  1871. A = B^2?  Of course, leading digits must be non-zero.
  1872.  
  1873. ==> arithmetic/digits/squares/length.22.s <==
  1874. No, the number of digits of A^2 must be of the form 3n or 3n-1.
  1875.  
  1876. ==> arithmetic/digits/squares/length.9.p <==
  1877. Is it possible to make a number and its square, using the digits from 1
  1878. through 9 exactly once?
  1879.  
  1880. ==> arithmetic/digits/squares/length.9.s <==
  1881. Yes, there are two such pairs: (567, 567^2=321489) and (854,854^2=729316).
  1882.